package com.example.smartcity.ui.AcNews.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.smartcity.R
import com.example.smartcity.ui.AcNews.model.NewsComment

class NewSCommentSRecyclerViewAdapter(
    val data: List<NewsComment>
) : RecyclerView.Adapter<NewSCommentSRecyclerViewAdapter.ViewHolder>(){
    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        // 获取控件
        val userName: TextView = view.findViewById(R.id.newsUserName)
        val userContent: TextView = view.findViewById(R.id.newsUserContent)
        val userTime: TextView = view.findViewById(R.id.newsUserTime)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.recyclerview_item_newsconment, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount() = data.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val listData = data[position]
        holder.userName.text = listData.newsTitle
        holder.userContent.text = listData.newsContent
        holder.userTime.text = listData.newsTime
    }
}